#include "head.h"


int do_login(client_status_t *status){


    char username[60]={0};
    char password[60]={0};

    printf("输入用户名:");
    scanf("%s",username);
    memcpy(status->user, username, strlen(username)  );

    printf("输入密码:");
    scanf("%s",password);
    memcpy(status->password, password, strlen(password)  );

    char ch;
    while((ch=getchar())!='\n');

    char clcmd[15]="/";
    memcpy(status->runtime_cmd, clcmd, strlen(clcmd)  );

    //send用户信息
    self_defined_pro_t *mes=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    strcat(mes->message,"username=");
    strcat(mes->message,username);
    strcat(mes->message,"&");
    strcat(mes->message,"password=");
    strcat(mes->message,password);
    mes->cmd=login;
    mes->message_len=strlen(mes->message);
    mes->para_num=3;

    int ret = send(status->socket_fd,mes,sizeof(self_defined_pro_t),MSG_NOSIGNAL);
    ERROR_CHECK(ret, -1, "send");


    self_defined_pro_t *server_mes=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    recv(status->socket_fd,server_mes,sizeof(self_defined_pro_t),MSG_WAITALL);

    if(server_mes->cmd == 200){
        printf("登录成功\n");
        status->login_status = 1; 
        memcpy(status->path, "/", 1);
    }else{
        printf("登录失败\n");
    }

    return 0;
}



